package com.ykh.mybbsdemo.controller;

import com.ykh.mybbsdemo.dao.pojo.po.SysUser;
import com.ykh.mybbsdemo.service.FocusedService;
import com.ykh.mybbsdemo.util.UserThreadLocal;
import com.ykh.mybbsdemo.dao.pojo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-06-08
 * Time: 13:32
 */
@RestController
@RequestMapping("focused")
public class FocusedController {

    @Autowired
    FocusedService focusedService;
    /**
     * 关注用户接口
     * @param id 被关注的用户id
     * @return
     */
    @PostMapping("add/{id}")
    public Result focusUser(@PathVariable("id")Long id) {
        SysUser sysUser = UserThreadLocal.get();
        if(sysUser == null){
            return Result.fail(405,"用户未登录");
        }
        return focusedService.focusUser(id, sysUser);
    }

    /**
     * 取消关注用户接口
     * @param id 被关注的用户id
     * @return
     */
    @PostMapping("cancel/{id}")
    public Result cancelFocus(@PathVariable("id")Long id) {
        SysUser sysUser = UserThreadLocal.get();
        if(sysUser == null){
            return Result.fail(405,"用户未登录");
        }
        return focusedService.cancelFocus(id, sysUser);
    }

    /**
     * 判断是否关注过该用户
     * @param id 被关注的用户id
     * @return
     */
    @PostMapping("isFocus/{id}")
    public Result isFocus(@PathVariable("id")Long id) {
        SysUser sysUser = UserThreadLocal.get();
        if(sysUser == null){
            return Result.fail(405,"用户未登录");
        }
        return focusedService.isFocus(id, sysUser);
    }

    /**
     * 获取自己关注的用户信息列表
     * @return
     */
    @PostMapping("getMyFocusList")
    public Result getMyFocusList() {
        SysUser sysUser = UserThreadLocal.get();
        if(sysUser == null){
            return Result.fail(405,"用户未登录");
        }
        return focusedService.getMyFocusList(sysUser);
    }

    /**
     * 获取关注自己的用户信息列表
     * @return
     */
    @PostMapping("getFocusedList")
    public Result getFocusedList() {
        SysUser sysUser = UserThreadLocal.get();
        if(sysUser == null){
            return Result.fail(405,"用户未登录");
        }
        return focusedService.getFocusedList(sysUser);
    }



}
